#include <iostream>
using namespace std;
typedef int Datetype ;
class Stack{
public:
    Stack(int capacity = 4)
    :m_capacity(capacity)
    {
        cout<<"Stack(int capacity = 4)"<<endl;
        m_array = new Datetype[m_capacity];
        m_size = 0;
    }
    Stack(const Stack& ST)//栈需要完成深拷贝
    {
        m_array = new Datetype[m_capacity = ST.m_capacity];
        m_size = ST.m_size;
    }
    void Push(Datetype x)
    {
        m_array[m_size++] = x;
    }
    ~Stack()
    {
        cout<<"~Stack"<<endl;
        delete [] m_array;
        m_array = nullptr;
        m_size = 0;
        m_capacity = 0;
    }
private:
Datetype* m_array;
int m_capacity;
int m_size = 0;
};


Stack* GetStack()
{
    Stack* a = new Stack(10);
    return a;
}
// class A{

// private:
// int m_a;
// };
// int main()
// {
//     A *p = new A[10];//这里释放要对应释放
//     delete p;
//     return 0;
// }


// int main()
// {
//     Stack * pst1 = (Stack*)operator new(sizeof(Stack));
//     new(pst1)Stack(4);//定位new，用于显式调用构造函数
//     pst1->~Stack();
//     operator delete (pst1);
//     return 0;
// }
class A{
public : 
    A(int a)
    :_a(a)
    {
        cout<<"A(int a)"<<endl;
    }
    A(const A& a1)
    :_a(a1._a)
    {
        cout<<"A(const A& a1)"<<endl;
    }
    ~A()
    {
        cout<<"~A"<<endl;
    }
private :
int _a = 0;
};

template<class T1,typename T2>
void func(T1 a,T2 b)
{
    return a+b;
}
int main(){
    A* a = new A[5]{1,2,3,4,5};
    delete []a;

    char* aa = new char[100];
    delete aa;//这种情况，既不会存在内存泄漏，也不会报错。但是用这种就不好
    return 0;
}

